home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b12
/
Util
/
CGI.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-09
|
8KB
|
282 lines
#pragma once
/*****
*
* Grant's CGI Framework (Common Grant Interface :-)
* http://arpp1.carleton.ca/grant/mac/grantscgi.html
*
* CGI.h
*
* standard types and function prototypes for cgi applications
* See the Read Me or CGI.c for instructions on using the CGI Utilities
*
* #include this file in your source files that need to access the cgi module
*
* This is a support file for "Grant's CGI Framework".
* Please see the license agreement that accompanies the distribution package
* for licensing details.
*
* Copyright ©1995 by Grant Neufeld
*
* http://arpp1.carleton.ca/grant/
* gneufeld@ccs.carleton.ca
* grant@acm.org
*
*****/
#include "MyConfiguration.h"
#if kCompileWithCGICode
#include <Threads.h>
/*** CONSTANT DECLARATIONS ***/
#define kCGIParamMaxSize 32769
#define kCGIHTTPMethodGet "GET"
#define kCGIHTTPMethodPost "POST"
#define kCGIHTTPMethodGetConditional "GET_CONDITIONAL"
#define kCGIFormFieldDelimiter '='
#define kCGIFormFieldSeparator '&'
/* Apple events */
#define kAEClassCGI 'WWWΩ'
#define kAEIDSearchDoc 'sdoc'
/* CGI event parameters */
#define kCGIpath_args '----'
#define kCGIhttp_search_args 'kfor'
#define kCGIusername 'user'
#define kCGIpassword 'pass'
#define kCGIfrom_user 'frmu'
#define kCGIclient_address 'addr'
#define kCGIpost_args 'post'
#define kCGImethod 'meth'
#define kCGIserver_name 'svnm'
#define kCGIserver_port 'svpt'
#define kCGIscript_name 'scnm'
#define kCGIcontent_type 'ctyp'
#define kCGIreferer 'refr'
#define kCGIuser_agent 'Agnt'
#define kCGIaction 'Kact'
#define kCGIaction_path 'Kapt'
#define kCGIclient_ip 'Kcip'
#define kCGIfull_request 'Kfrq'
#define kCGIversion 'Pvrs'
#define kCGIconnection 'Kcid'
/* for an official listing of the maximum sizes for CGI parameters,
<http://www.biap.com/datapig/mrwheat/cgi_params.html> */
#define kCGIMaxpath_args 1024
#define kCGIMaxhttp_search_args 1024
#define kCGIMaxusername 32
#define kCGIMaxpassword 32
#define kCGIMaxfrom_user 128
#define kCGIMaxclient_address 256
#define kCGIMaxpost_args 32768
#define kCGIMaxmethod 32
#define kCGIMaxserver_name 256 /* server address? */
#define kCGIMaxserver_port 16
#define kCGIMaxscript_name 1024
#define kCGIMaxcontent_type 64
#define kCGIMaxreferer 1024
#define kCGIMaxuser_agent 256
#define kCGIMaxaction 32
#define kCGIMaxaction_path 1024
#define kCGIMaxclient_ip 32
#define kCGIMaxfull_request 4096
#define kCGIMaxversion 32768 /* ••• missing the correct value */
#define kCGIMaxconnection 4
/* Send Partial event */
#define kMyAESendPartial 'SPar'
#define kCGIPartialData '----'
#define kConnectionIDKeyword 'Kcid'
#define kMoreKeyword 'Kmor'
#define kCGIPartialStartString "<SEND_PARTIAL>"
/*** TYPE DECLARATIONS ***/
#if kCompileWithCGIFormHandling
typedef struct
{
char * name;
char * value;
} CGIFormField;
#endif
#if kCompileWithCGImethod
typedef enum
{
HTTP_UNDEFINED,
HTTP_get,
HTTP_post,
HTTP_getConditional
} HTTPMethod;
#endif
typedef struct
{
/* the following fields should be treated as public read-only */
#if kCompileWithCGIpath_args
char * path_args; /* '----' path_args */
#endif
#if kCompileWithCGIhttp_search_args
char * http_search_args; /* 'kfor' http_search_args */
#endif
#if kCompileWithCGIusername
char username[kCGIMaxusername]; /* 'user' username */
#endif
#if kCompileWithCGIpassword
char password[kCGIMaxpassword]; /* 'pass' password */
#endif
#if kCompileWithCGIfrom_user
char * from_user; /* 'frmu' from_user */
#endif
#if kCompileWithCGIclient_address
char * client_address; /* 'addr' client_address */
#endif
#if kCompileWithCGIpost_args
char * post_args; /* 'post' post_args */
#endif
#if kCompileWithCGImethod
HTTPMethod method; /* 'meth' method */
#endif
#if kCompileWithCGIserver_name
char * server_name; /* 'svnm' server_name */
#endif
#if kCompileWithCGIserver_port
short server_port; /* 'svpt' server_port */
#endif
#if kCompileWithCGIscript_name
char * script_name; /* 'scnm' script_name */
#endif
#if kCompileWithCGIcontent_type
char * content_type; /* 'ctyp' content_type */
#endif
#if kCompileWithCGIreferer
char * referer; /* 'refr' referer */
#endif
#if kCompileWithCGIuser_agent
char * user_agent; /* 'Agnt' user_agent */
#endif
#if kCompileWithCGIActionSupport
char action[kCGIMaxaction]; /* 'Kact' action */
char * action_path; /* 'Kapt' action_path */
#endif
#if kCompileWithCGIclient_ip
char client_ip[kCGIMaxclient_ip]; /* 'Kcip' client_ip */
#endif
#if kCompileWithCGIfull_request
char * full_request; /* 'Kfrq' full_request */
#endif
#if kCompileWithCGIversion
char * version; /* 'Pvrs' version */
#endif
#if kCompileWithCGISendPartial
long connection; /* 'Kcid' connection */
#endif
#if kCompileWithCGIFormHandling
CGIFormField * formFields; /* the fields from form submission */
long totalFields; /* total number of fields */
#endif
/* private fields that probably should not be touched outside
of the CGI.c file */
AppleEvent appleEvent; /* originating appleEvent */
AppleEvent replyEvent; /* apple event reply record */
ThreadID thread; /* ID of the CGI handle's thread */
/* public fields to be filled in */
char * responseData; /* data to return to the client */
long responseSize; /* size in bytes of the response */
} CGIrecord;
typedef CGIrecord ** CGIHdl;
/*** GLOBAL DECLARATIONS ***/
#ifdef __CGISegment__
#define _GLOBAL_
#else
#define _GLOBAL_ extern
#endif
/* these are globals for holding the standard http headers.
One of the headers must be prepended to the data returned in the Apple Event */
_GLOBAL_ Str255 gHTTPHeaderOK; /* use data returned after header */
_GLOBAL_ Str255 gHTTPHeaderRedirect; /* redirect client to different url */
_GLOBAL_ Str255 gHTTPHeaderErr; /* an application level error */
#if kCompileWithCGISendPartial
_GLOBAL_ Str255 gHTTPHeaderPush; /* multipart server push */
#endif
_GLOBAL_ long gHTTPHeaderOKSize;
_GLOBAL_ long gHTTPHeaderRedirectSize;
_GLOBAL_ long gHTTPHeaderErrSize;
#if kCompileWithCGISendPartial
_GLOBAL_ long gHTTPHeaderPushSize;
#endif
#undef _GLOBAL_
/*** FUNCTION PROTOTYPES ***/
OSErr InitCGIUtil ( void );
#if kCompileWithCGIFormHandling
CGIFormField * CGIFormFieldsFromArgs ( char *, long *, short * );
CGIFormField * CGIFormFieldsFindRecord ( CGIHdl, char * );
void CGIFormFieldsDispose ( CGIFormField * );
#endif /* kCompileWithCGIFormHandling */
void CGIDecodeSpecialChars ( char * );
char * CGIEncodeSpecialChars ( char * );
void CGICharToHex ( unsigned char, char * );
pascal OSErr CGIAESearchDoc ( AppleEvent *, AppleEvent *, long );
#if kCompileWithCGISendPartial
OSErr CGIAESendPartial ( CGIHdl, char *, long, Boolean );
#endif /* kCompileWithCGISendPartial */
/*** EXTERNAL FUNCTION PROTOTYPES ***/
/* this is the function which you must define for your particular application */
void MyCGIProcess ( CGIHdl );
/* this function is called once at startup time.
Put any initialization you need to do in it. */
Boolean MyCGIStartup ( void );
/* this function is called at quitting time.
Put any cleanup you need to do in it. */
Boolean MyCGIQuit ( Boolean );
#else /* if not kCompileWithCGICode */
/* these are defined like this here so the StartupApplication function
doesn't have to be messed with when compiling without the CGI module */
#define InitCGIUtil() (noErr)
#define MyCGIStartup() (true)
#define MyCGIQuit() (true)
#endif /* kCompileWithCGICode */
/*** EOF ***/